<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/28
 * Time: 13:39
 */

namespace Home\Controller;


class LogController extends HomeController
{
    public function index(){
        $this->meta_title = '系统日志';
        $this->display();
    }

    public function logList($limit, $offset, $begin_time = null, $end_time = null, $real_name = null, $ip = null, $describe = null, $func = null){

        empty($begin_time) && $begin_time = '1970-01-01 00:00:00';
        empty($end_time) && $end_time = time_format(NOW_TIME);
        if(empty($end_time)){
            $end_time = time_format(NOW_TIME);
        }else{
            $end_time = date('Y-m-d', strtotime("+1day", strtotime($end_time)));
        }
        $map['operation_time'] = array('between', array($begin_time,$end_time));

        empty($real_name) or $map['real_name'] = array('like', "%{$real_name}%");
        empty($ip) or $map['ip'] = array('like', "%{$ip}%");
        empty($func) or $map['function'] = array('like', "%{$func}%");
        empty($describe) or $map['describe'] = array('like', "%{$describe}%");
        $field = 'ol.log_id, ol.user_id, ol.IP, ol.function, ol.describe, ol.operation_time, u.real_name';
        $model = D('OperationLog')->alias('ol');
        $record = $model->join('user u on ol.user_id=u.user_id')->where($map)->order('operation_time desc')->field($field)->limit($offset, $limit)->select();
        $sql = $model->getLastSql();
        $total_count = $model->alias('ol')->join('user u on ol.user_id=u.user_id')->where($map)->count();
        $sql = $model->getLastSql();
        $result['rows'] = $record;
        $result['total'] = $total_count;
        $this->ajaxReturn($result);
    }

}